//
//  SystemUtil.m
//  PigMarket
//
//  Created by Felix on 2019/4/11.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "SystemUtil.h"
#import "OpenUDID.h"
#import "ConfigManager.h"

@implementation SystemUtil

+ (NSString *)getUniqueId {
    
    NSString *uniqueId = @"";
    
    NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
    
#define kUSERUDIDKEY @"kUSERUDIDKEY"
    NSString *udid = [def objectForKey:kUSERUDIDKEY];
    if ([udid length] > 0) {
        uniqueId = udid;
    } else {
        udid = [[OpenUDID value] stringByReplacingOccurrencesOfString:@"-" withString:@""];
        if ([udid length] > 0) {
            [def setObject:udid forKey:kUSERUDIDKEY];
            [def synchronize];
        }
        uniqueId = udid;
    }
    
    return uniqueId;
    
}

+ (NSString *)getAppName {
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    NSString *appName = [infoDictionary objectForKey:@"CFBundleDisplayName"];
    return appName;
}

+ (NSString *)getAppVersion {
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    NSString *appVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    return appVersion;
}

+ (NSString *)getAppVersionNum {
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    NSString *appVersionNum = [infoDictionary objectForKey:@"CFBundleVersion"];
    return appVersionNum;
}

+ (NSString *)getHomePath {
    
    return NSHomeDirectory();
}

+ (NSString *)getDocumentPath {
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    return [paths objectAtIndex:0];
}

+ (NSString *)getCachePath {
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    return [paths objectAtIndex:0];
}

+ (NSString *)getLibraryPath {
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    return [paths objectAtIndex:0];
}

+ (NSString *)getTmpPath {
    
    return NSTemporaryDirectory();
}

@end
